home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-17 | 6.6 KB | 166 lines | [TEXT/KAHL] |
- alloc_gla.c Read Me
- -------------------
-
- This file is a replacement for the current alloc.c, and replaces the routines
- malloc, realloc, calloc, and free with a new version which (1) validates its
- zone(s) on calls to its routines, (2) is application-configurable to return
- memory zones to the Macintosh application heap when they are freed, (3) has an
- application-configurable "crossover" size, where memory requests larger than a
- certain size allocate a zone to that single memory request. Also, it is
- written in straight C, rather than a mixture of C and 68K assembly. It is also
- faster during malloc than the current version.
-
- The biggest advantages to this version are its heap validation and its
- alignment of blocks on an 8-byte boundary, which has HUGE benefits when working
- with doubles on a PowerPC (and helps the 68K processor as well). When NDEBUG is
- not defined, it verifies that valid values are in its zone header and memory
- block entries. When freeing memory, it validates that the beginning of the
- next block hasn't been overwritten.
-
- How to use
- ----------
-
- I now provide an AppleScript application which will open the appropriate ANSI
- libraries for both TPM and SPM and update them to use alloc_gla.c instead of
- alloc.c.
-
- You will still need to update your projects to use the new ANSI libraries.
-
- Description and New Information
- -------------------------------
-
- This code uses a series of linked memory "zones", which are then suballocated
- to reduce the demands on the Macintosh Memory manager for small memory
- allocation requests.
-
- There are two global variables which allow you to configure the behavior of
- the new alloc.c. These global variables are:
-
- unsigned long gMaxBlockSize This configures the "crossover" size for the
- application. By default, this value is set to
- 32768, which means that memory requests smaller
- than this size will be sub-allocated from a
- gMaxBlockSize zone. Requests larger than
- gMaxBlockSize will be allocated from their own
- zone.
-
- Boolean gRestoreMemToHeap This flag configures the behavior of the free
- routine to return freed memory zones back to the
- Macintosh Memory manager. By default, this flag
- is set to true so that freed zones will be
- returned to the application heap.
-
- There are also two new routines for preallocating and cleaning up freed zones.
- This allows you to specify a pool of non-relocatable memory at application
- start which can be used for objects and memory requests. These two routines
- are:
-
- void *prealloc(size_t size) This routine will allocate a zone large enough
- to satisfy a memory request for size bytes. You
- can use this to preallocate non-relocatable
- memory for use by your application and document
- objects.
-
- void cleanupalloc(void) This routine will return to the application heap
- all zones which have no memory suballocated out
- of them.
-
- There is also a debugging routine which is available to your application if
- you define the compile-time flag __DUMPBLOCKS__ to 1. The routine:
-
- Boolean DumpBlocks(void)
-
- will then become available and will display the current contents of the memory
- zone(s) on the console window, and return a flag whether all the zone(s) were
- valid.
-
- WARNING! Do not put DumpBlocks inside the memory routines! The
- console I/O routines also make use of malloc and free, and
- can cause havoc with the memory zones!
-
- WARNING! These memory routines have been tested, but not to the
- thoroughness we require for released software. If you have
- problems with this code, please send mail to
- SYMGlenn@devtools.symantec.com so that any bugs can be
- squashed.
-
- Release Notes
- -------------
-
- Release 1.0.10
- -------------
- * Added functionality for big blocks to automatically get returned to
- the application zone, regardless of the setting of gRestoreMemToHeap.
- * When allocating memory, I check to see if the existing zone(s) could
- satisfy the request before checking if the size is greater than the
- crossover size.
-
- Release 1.0.9
- -------------
- * I missed yet one more assignment in 1.0.8 when the next block isn't
- a free block when freeing.
-
- Release 1.0.8
- -------------
- * I missed an assignment in 1.0.7 when fixing the bug in free where, if the
- next block was the end of zone, it wasn't setting the size correctly for
- the newly freed block.
- * I now provide an AppleScript to update the ANSI libraries for both TPM and
- SPM to use alloc_gla.c instead of alloc.c.
-
- Release 1.0.7
- -------------
- * There was a bug in free when the block that was being freed was the last
- block in a zone. It wasn't getting combined with the previous block if
- the previous block was also a free block. (thanks DF)
-
- Release 1.0.6
- -------------
- * Commented out the _UseAssert_ and _Debug_Alloc_GLA__ macros, since they
- shouldn't have been uncommented in the final version.
-
- Release 1.0.5
- -------------
- * Bug fixed in alloc when the block is getting initialized. It was allocating
- space for a block of the specified size, but was initializing for a maximum
- block size of sizeof(MemBlock) bytes smaller.
- * Bug fixed in calculating the 8 byte size (alignment). It was adding 8, which
- could allocate 8 bytes more than was necessary, if the requested size was
- already a multiple of 8.
-
- Release 1.0.4
- -------------
- * Bug fixed in realloc when the block following this block was the end
- of the zone, which is a special "free" block. Now special casing for
- end of zone.
- * Bug fixed in realloc when the block following this block was free, but
- wasn't large enough to satisfy the request for the resize. Now mallocs
- a new block if this is the case.
- * Made sure all asserts were inside conditional compile flag.
- * Added CheckBlocks routine for testing allocations without I/O.
- * Sizes are now a multiple of 8, which means that addresses should also
- be a multiple of 8. This will improve performance on PowerPC with
- doubles.
-
- Release 1.0.3
- -------------
- * Improved realloc performance when the next block is a free block since
- realloc will now manipulate the free block size rather than moving the
- current block if it is growing.
- * Fixed many annoying bugs in realloc when the new size would make the
- size of the following free block smaller than 2 bytes.
-
- Release 1.0.2
- -------------
- * Fixed problems with blocks larger than gMaxBlockSize. They were still
- marked as free blocks, even though they were in use.
-
- Release 1.0.1
- -------------
- * Fixed problems with splitting a free block when the first free block
- would be close to the same size as the block being split. The second
- block header would overwrite the beginne next block header.
-
- Release 1.0
- -----------
- * Initial release on Symantec C++ 8.0 CD